Dev - #14
Conversation
Reviewer's GuideRefactors extension activation to lazy-initialize heavy runtime components, introduces an esbuild-based bundling and deps-copy pipeline to make pnpm-based runtime dependencies work with vsce packaging, updates CI/release workflows and devDependencies, and adjusts tree-sitter integration to load from packaged deps instead of node_modules with additional safety checks. Sequence diagram for lazy initialization during extension activation and command executionsequenceDiagram
actor VSCode
participant Extension
participant EventProcessor
participant TreeSitterManager
participant DatabaseManager
VSCode->>Extension: activate(context)
Extension->>Extension: vscode.commands.registerCommand(codepulse.openDashboard)
Extension->>Extension: vscode.commands.registerCommand(codepulse.exportJson)
Extension->>Extension: vscode.commands.registerCommand(codepulse.exportCsv)
Extension->>Extension: vscode.commands.registerCommand(codepulse.purgeLogs)
Extension->>Extension: vscode.languages.registerCodeLensProvider()
Extension->>Extension: vscode.languages.registerHoverProvider()
Extension->>EventProcessor: new EventProcessor()
Extension->>EventProcessor: context.subscriptions.push(dispose)
Extension->>Extension: ensureInitialized(context)
Extension->>TreeSitterManager: TreeSitterManager.getInstance()
Extension->>TreeSitterManager: initialize(context)
Extension->>DatabaseManager: DatabaseManager.getInstance()
Extension->>DatabaseManager: initialize(storageDir)
Extension->>EventProcessor: eventProcessor.activate()
Extension->>Extension: showDashboard(context)
VSCode->>Extension: vscode.commands.executeCommand(codepulse.openDashboard)
Extension->>Extension: ensureInitialized(context)
Extension->>TreeSitterManager: initialize(context) [if not initialized]
Extension->>DatabaseManager: initialize(storageDir) [if not initialized]
Extension->>Extension: showDashboard(context)
VSCode->>Extension: deactivate()
Extension->>EventProcessor: eventProcessor.deactivate()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The change to read WASM binaries from
deps/(inwasmHelper.ts) means dev runs withoutcopy-deps.mjswill fail; consider falling back tonode_moduleswhendeps/is missing so the extension can run directly from the workspace. - In the new command implementations (
exportJson,exportCsv,purgeLogs),ensureInitializedis awaited but errors are not surfaced to the user; mirroring the try/catch andshowErrorMessagebehavior used inopenDashboardwould make failures more user-friendly and avoid silent command failures. - The TreeSitter initialization error message constructed in
parser.tsis helpful but currently throws the original error after showing a generic message; consider including the original error details in the user-facing message to aid debugging when runtime dependencies are missing or mispackaged.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The change to read WASM binaries from `deps/` (in `wasmHelper.ts`) means dev runs without `copy-deps.mjs` will fail; consider falling back to `node_modules` when `deps/` is missing so the extension can run directly from the workspace.
- In the new command implementations (`exportJson`, `exportCsv`, `purgeLogs`), `ensureInitialized` is awaited but errors are not surfaced to the user; mirroring the try/catch and `showErrorMessage` behavior used in `openDashboard` would make failures more user-friendly and avoid silent command failures.
- The TreeSitter initialization error message constructed in `parser.ts` is helpful but currently throws the original error after showing a generic message; consider including the original error details in the user-facing message to aid debugging when runtime dependencies are missing or mispackaged.
## Individual Comments
### Comment 1
<location path="src/extension.ts" line_range="228-221" />
<code_context>
+ }
}),
- vscode.commands.registerCommand('codepulse.exportJson', () => {
+ vscode.commands.registerCommand('codepulse.exportJson', async () => {
+ await ensureInitialized(context);
void exportJson();
}),
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Command handlers using `ensureInitialized` lack error handling, which can surface unhandled rejections to users.
For `codepulse.exportJson`, `codepulse.exportCsv`, and `codepulse.purgeLogs`, `await ensureInitialized(context)` is not wrapped in error handling. If initialization fails (e.g., missing dependencies or DB issues), the command will reject without clear user feedback and may surface opaque errors in the extension host. Please align these handlers with `openDashboard` by using try/catch and `showErrorMessage` to handle initialization failures consistently and avoid unhandled promise rejections.
Suggested implementation:
```typescript
vscode.commands.registerCommand('codepulse.exportJson', async () => {
try {
await ensureInitialized(context);
void exportJson();
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
void vscode.window.showErrorMessage(`[CodePulse] Failed to export JSON: ${msg}`);
}
}),
```
```typescript
vscode.commands.registerCommand('codepulse.exportCsv', async () => {
try {
await ensureInitialized(context);
void exportCsv();
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
void vscode.window.showErrorMessage(`[CodePulse] Failed to export CSV: ${msg}`);
}
}),
```
To fully align with the comment, you should also update the `codepulse.purgeLogs` command handler (wherever it is defined in `src/extension.ts`) to follow the same pattern:
- Wrap `await ensureInitialized(context)` and the purge operation in a `try` block.
- On error, compute `msg` using the same `err instanceof Error ? err.message : String(err)` pattern.
- Use `vscode.window.showErrorMessage` with a message like `[CodePulse] Failed to purge logs: ${msg}`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| showDashboard(context); | ||
| vscode.commands.registerCommand('codepulse.openDashboard', async () => { | ||
| try { | ||
| await ensureInitialized(context); |
There was a problem hiding this comment.
suggestion (bug_risk): Command handlers using ensureInitialized lack error handling, which can surface unhandled rejections to users.
For codepulse.exportJson, codepulse.exportCsv, and codepulse.purgeLogs, await ensureInitialized(context) is not wrapped in error handling. If initialization fails (e.g., missing dependencies or DB issues), the command will reject without clear user feedback and may surface opaque errors in the extension host. Please align these handlers with openDashboard by using try/catch and showErrorMessage to handle initialization failures consistently and avoid unhandled promise rejections.
Suggested implementation:
vscode.commands.registerCommand('codepulse.exportJson', async () => {
try {
await ensureInitialized(context);
void exportJson();
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
void vscode.window.showErrorMessage(`[CodePulse] Failed to export JSON: ${msg}`);
}
}), vscode.commands.registerCommand('codepulse.exportCsv', async () => {
try {
await ensureInitialized(context);
void exportCsv();
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
void vscode.window.showErrorMessage(`[CodePulse] Failed to export CSV: ${msg}`);
}
}),To fully align with the comment, you should also update the codepulse.purgeLogs command handler (wherever it is defined in src/extension.ts) to follow the same pattern:
- Wrap
await ensureInitialized(context)and the purge operation in atryblock. - On error, compute
msgusing the sameerr instanceof Error ? err.message : String(err)pattern. - Use
vscode.window.showErrorMessagewith a message like[CodePulse] Failed to purge logs: ${msg}.
Summary by Sourcery
Bundle the extension with esbuild, ship runtime WASM dependencies via a dedicated deps/ directory, and adjust activation/CI/release flows to improve reliability of initialization and packaging.
New Features:
Enhancements:
Build:
CI: